package com.hz.house.bean.dto;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
 * @Author dql
 * @Date 2019/11/14 10:24
 */
@Data
@ApiModel("列表分页返回")
public class PageDTO<T> {

    public PageDTO(PageInfo pageInfo, List<T> data){
        this.data = data;
        pageIndex = pageInfo.getPageNum();
        totalPages = pageInfo.getPages();
        totalCount = pageInfo.getTotal();
        hasNext = pageInfo.isHasNextPage();
        hasPrev = pageInfo.isHasPreviousPage();
    }

    public PageDTO(PageInfo<T> pageInfo){
        data = pageInfo.getList();
        pageIndex = pageInfo.getPageNum();
        totalPages = pageInfo.getPages();
        totalCount = pageInfo.getTotal();
        hasNext = pageInfo.isHasNextPage();
        hasPrev = pageInfo.isHasPreviousPage();
    }

    public PageDTO(List<T> data, long pageIndex, long totalPages, long totalCount, boolean hasNext, boolean hasPrev) {
        this.data = data;
        this.pageIndex = pageIndex;
        this.totalPages = totalPages;
        this.totalCount = totalCount;
        this.hasNext = hasNext;
        this.hasPrev = hasPrev;
    }

    @ApiModelProperty("返回数据")
    private List<T> data;
    @ApiModelProperty("当前第几页")
    private long pageIndex;
    @ApiModelProperty("总页数")
    private long totalPages;
    @ApiModelProperty("总条数")
    private long totalCount;
    @ApiModelProperty("是否有下一页")
    private boolean hasNext;
    @ApiModelProperty("是否有前一页")
    private boolean hasPrev;
}
